//
//  ViewController.m
//  homeWork-18
//
//  Created by 鹏飞罗 on 16/8/8.
//  Copyright © 2016年 罗鹏飞. All rights reserved.
//

#import "ViewController.h"
#import "DetailPersonViewController.h"
#import "SQLiteManager.h"
#define kTableViewCellReuse @"reuse"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) SQLiteManager *dataBaseManager;
@property (nonatomic, strong) NSMutableArray *contactArray;
@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated {
    [self handleData];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self handleData];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"通讯录";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"添加" style:UIBarButtonItemStylePlain target:self action:@selector(addPerson)];
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kTableViewCellReuse];
    
    
}
- (void)handleData {
    _contactArray = [NSMutableArray array];
    _dataBaseManager = [SQLiteManager sharedManger];
    [_dataBaseManager openSQLite3];
  _contactArray =  [_dataBaseManager selectAll];
    
}

- (void)addPerson {
    DetailPersonViewController *detailVC = [[DetailPersonViewController alloc] init];
    [self.navigationController pushViewController:detailVC animated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCellReuse];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
